package com.ruoyi.bussiness.service.impl;

import com.ruoyi.bussiness.service.IFfmpegConver;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import java.io.IOException;

/**
 * @author 12290
 */
@Service
public class FfmpegConver implements IFfmpegConver {
    private final Logger logger = LoggerFactory.getLogger(FfmpegConver.class);
    @Override
    public void convertAudio(String inputFile, String outputFile) {
        ProcessBuilder processBuilder = new ProcessBuilder(
                "ffmpeg", "-i", inputFile,
                "-ar", "16000",
                "-acodec", "pcm_s16le",
                "-ac", "1",
                outputFile);

        try {
            Process process = processBuilder.start();
            int exitCode = process.waitFor();
            if (exitCode == 0) {
                logger.info("Audio conversion successful");
            } else {
                logger.error("Audio conversion failed");
            }
        } catch (IOException | InterruptedException e) {
            logger.error("Error during audio conversion", e);
            Thread.currentThread().interrupt();
        }


    }
}
